package com.lalilu.homework4;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.lalilu.homework4.utils.FastBlur;
import com.lalilu.homework4.utils.StatusBarUtil;

public class MainActivity extends AppCompatActivity {
    public final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setStatusBarColor(this);
        setContentView(R.layout.activity_registry);
        Log.i(TAG, "onCreate");


        View background = findViewById(R.id.background);
        Button login = findViewById(R.id.button_login);
        EditText username = findViewById(R.id.editTextTextPersonName);
        EditText checkcode = findViewById(R.id.editTextTextCheckCode);
        EditText password = findViewById(R.id.editTextTextPassword);

        background.post(() -> {
            Bitmap temp = BitmapFactory.decodeResource(getResources(), R.drawable._7954130_p0__compress, getBitmapOption(8));
            background.setBackground(new BitmapDrawable(FastBlur.doBlur(temp, 50, false)));
        });

        login.setOnClickListener((view) -> {
            Intent intent = new Intent(MainActivity.this, RegistryInfoShow.class);
            intent.putExtra("com.lalilu.homework4.username", username.getText());
            intent.putExtra("com.lalilu.homework4.checkcode", checkcode.getText());
            intent.putExtra("com.lalilu.homework4.password", password.getText());
            this.startActivity(intent);
        });
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "onResume");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, "onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }

    private BitmapFactory.Options getBitmapOption(int inSampleSize) {
        System.gc();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPurgeable = true;
        options.inSampleSize = inSampleSize;
        return options;
    }
}